/*
** clear.c for starwars in /u/all/caille_c/cu/public/colle
** 
** Made by carole cailleux
** Login   <caille_c@epitech.net>
** 
** Started on  Mon Apr 26 20:53:48 2010 carole cailleux
** Last update Mon Apr 26 21:58:27 2010 mickael pucheu
*/

#include <stdio.h>
#include <stdlib.h>
#include <termcap.h>
#include "starwars.h"

int		my_outc(int c)
{
  my_putchar(c);
  return (c);
}

char		*my_getenv(char *assign)
{
  char		*res;
  extern char	**environ;

  res = get_content_env(environ, assign);
  if (res == 0)
    {
      my_puterror("Error with my_getenv\n");
      exit(1);
    }
  return (res);
}

char		*get_content_env(char **environ, char *name_content)
{
  int		i;
  int		j;
  char		*content;
  char		prefix[64];

  i = 0;
  while (environ[i])
    {
      j = 0;
      while (environ[i][j] && environ[i][j] != '=')
        {
          prefix[j] = environ[i][j];
          j++;
        }
      prefix[j] = '\0';
      if (compare_str(name_content, prefix))
        {
          content = my_strdup(&environ[i][j + 1]);
          return (content);
        }
      i++;
    }
  return (0);
}

void		clear_screen()
{
  char		*clear;
  char		*area;
  char		t[4096];
  char		*term;
  char		bp[1024];

  area = t;
  term = getenv("TERM");
  tgetent(bp, term);
  clear = tgetstr("cl", &area);
  tputs(clear, 1, my_outc);
}
